import os

os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
from skimage import io, transform
import tensorflow as tf
import numpy as np

# 图片路径
path1 = "D:/项目/python/拍图识花/flower_photos/daisy/5547758_eea9edfd54_n.jpg"
path2 = "D:/项目/python/拍图识花/flower_photos/dandelion/7355522_b66e5d3078_m.jpg"
path3 = "D:/项目/python/拍图识花/flower_photos/roses/12240303_80d87f77a3_n.jpg"
path4 = "D:/项目/python/拍图识花/flower_photos/sunflowers/6953297_8576bf4ea3.jpg"
path5 = "D:/项目/python/拍图识花/flower_photos/tulips/10791227_7168491604.jpg"

# 类别字典
flower_dict = {0: "daisy", 1: "dandelion", 2: "roses", 3: "sunflowers", 4: "tulips"}
w, h, c = 100, 100, 3


def read_one_image(path):
    img = io.imread(path)
    img = transform.resize(img, (w, h))
    return np.asarray(img)


# 加载模型（使用TF2.x方式）
model = tf.keras.models.load_model(
    "D:/项目/python/拍图识花/flower_model/flower_model.keras"
)

# 准备数据
data = []
for path in [path1, path2, path3, path4, path5]:
    img = read_one_image(path)
    data.append(img)
data = np.array(data)

# 预测
predictions = model.predict(data)

# 输出结果
for i, pred in enumerate(predictions):
    class_id = np.argmax(pred)
    print(f"第{i+1}张图片的预测结果为: {flower_dict[class_id]}")
    print(f"各类别概率: {pred}")
